﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


class CombinationsOfKDistinctElements
{
    //Exercise 21. Write a program that reads two numbers N and K and generates all the combinations of K distinct elements from 
    //the set [1..N]. Example:	N = 5, K = 2 -> {1, 2}, {1, 3}, {1, 4}, {1, 5}, {2, 3}, {2, 4}, {2, 5}, {3, 4}, {3, 5}, {4, 5}

    static int N;
    static int K;
    static int[] array;

    static void Main()
    {
        Console.Write("Enter N: ");
        N = int.Parse(Console.ReadLine());
        Console.Write("Enter K: ");
        K = int.Parse(Console.ReadLine());

        int[] array = new int[K];

        NestedArrays(array, 0, 1);
    }

    private static void PrintArray(int[] array)
    {
        for (int i = 0; i < array.Length; i++)
        {
            Console.Write(array[i] + " ");
        }
        Console.WriteLine();
    }

    static void NestedArrays(int[] array, int currentArray, int currentNumber)
    {
        if (currentArray == array.Length)
        {
            PrintArray(array);
        }
        else
        {
            for (int counter = currentNumber; counter <= N; counter++)
            {
                array[currentArray] = counter;
                NestedArrays(array, currentArray + 1, counter + 1);
            }
        }
    }

}

